<?php
namespace Admin\Controller;
use Admin\Controller\BaseController;

class UserController extends BaseController {
    //private $model;
    public function _initialize(){
      //$this->model=D('user');
      $this->tbl='user';
      $this->model=D($this->tbl);
      parent::_initialize();
    }
    public function index(){
  //   $usersmodel=M('user');
   //  $users=$usersmodel->order('zhr_id desc')->select();
    // $this->users=$users;
    // $this->display();
      parent::index($this->tbl);
    }
    public function userlist(){
  //   $usersmodel=M('user');
	 //  $users=$usersmodel->order('zhr_id desc')->select();
		// $this->users=$users;
		// $this->display();
      parent::showlist($this->tbl,'zhr_id desc');
    }
    public function view(){
       $id=I('get.id');
    }
     public function form(){
       parent::form($this->tbl);
       // $this->display();
    }
        
    public function add(){
      parent::add($this->tbl,'admin.php/user/userlist','zhr_photo');
      // $data=I('post.');
      // if(!empty($_FILES['zhr_photo']))
      // {
      //   $data['zhr_photo']=uploadfile('zhr_photo',150);
      // }
      
      // // dump($data);exit();
      //  //$data['zhr_username']=I('post.uname');前面表单中for属性写的是uname，则需要转化一下
      //  // //$this->model=M('user');
      //  if ($this->model->create($data)) {
      //  	$this->model->add();
      //  	$this->success('创建成功',U('admin.php/user/userlist')); }
      //  else  $this->error($this->model->getError());
    }

   
    public function mod(){
      parent::mod($this->tbl);
       // $id=I('get.id');
       // ////$this->model=M('user');
       // $one=$this->model->find($id);

       // // dump($id);exit;//调试程序
       // $this->assign('one',$one);
       // $this->display();

    }
    public function update(){
      //parent::update($this->tbl,'admin.php/user/userlist','zhr_photo');
       $data=I('post.');
      //  $this->model=M('user');
      if(!empty($_FILES['zhr_photo']['name']))
      {
        $data['zhr_photo']=uploadfile('zhr_photo',150);
      }
      //  //$data['hobby']=implode(',', $data['hobby']);
      //  //dump($data);exit;
      //  ////
      //  // $user=$this->model->create($data);
       if ($this->model->create($data)) {
       	$this->model->save();
       	$this->success('更新成功',U('admin.php/user/userlist'));
       }
       else  $this->error($this->model->getError());
    }

     public function delete(){
      parent::delete($this->tbl);
       // $id=I('get.id',0);
       // //$this->model=M('user');
       // $result=$this->model->delete($id);
       // // M('user')->delete(I('get.id'));
       // if($result){
       // 	$this->success('删除成功',U('admin.php/user/userlist'));
       // }
       //  else  $this->error($this->model->getError());
    }

    public function search(){
       parent::search($this->tbl,'search_key');

       // $key=I('post.search_key');
       // $sql="select * from user where zhr_username like '%".$key."%'";
       // $data=M()->query($sql);
       // // M()->execute($sql);
       // $this->assign('users',$data);
       // $this->display();
    }



    
}
